#include "Door.h"

#include <iostream>

Door::Door(int x, int y):
	GameObject(x, y, Type_Door),
	keyType(Player::InventoryItem_Key)
{
}


Door::Door(int x, int y, Player::InventoryItem keyType):
	GameObject(x, y, Type_Door),
	keyType(keyType)
{
}


Door::~Door()
{
}


void Door::handleCollision(GameObject* gameObject)
{
	if (gameObject->getType() == Type_Player)
	{
		destroy();
		static_cast<Player*>(gameObject)->removeFromInventory(keyType);
	}
}


bool Door::isPassable(const GameObject* gameObject) const
{
	if (gameObject->getType() == Type_Player)
	{
		return static_cast<const Player*>(gameObject)->hasInInventory(keyType);
	}
	return false;
}


void Door::drawObject(int row, int col) const
{
	drawSquare(row, col);

	std::vector<drawPoint> points;

	setColor(0,0,0);

	// Doorknob.
	points.push_back(drawPoint(col + 0.1, row + 0.5, 0));
	points.push_back(drawPoint(col + 0.2, row + 0.6, 0));
	points.push_back(drawPoint(col + 0.3, row + 0.5, 0));
	points.push_back(drawPoint(col + 0.2, row + 0.4, 0));

	drawInMode(GL_QUADS, points);
}
